# # import json
# # data={
# #     1:"2",
# #     2:{'2':1},
# # }
# # for r,c in json.loads(json.dumps(data)).items():
# #     print(c,r)
#
#
# a=(1,2)
# print(a[0])
# from typing import Optional
#
#
# def a(a,b):
#     print(a,b)
# def b(a,B:Optional[int]):
#     print(a)
# MAPPER={
#     'a':a,
#     'b':b,
# }
# data=MAPPER.get('b')('1')
from datetime import datetime

# a=(1,2,3)
# print(a(0))
# test= [
#         [b'6fe1a78e-a903-4d72-986c-4c7b1a4d5e74',
#
#
#         [(b'1745462087907-0', {b'last_stream': b'0'}), (b'1745462145128-0', {b'last_stream': b'0'}),
#        (b'1745462254272-0', {b'last_stream': b'0'}), (b'1745462268017-0', {b'last_stream': b'0'}),
#        (b'1745462316063-0', {b'last_stream': b'0'})]
#
#          ]
#     ]
#
# print(test[0][0])
# a='i'
# b='i'
# print(a &  b)

    # class Point:
    #     def __init__(self, x, y):
    #         self.x = x
    #         self.y = y
    #
    #     def __eq__(self, other):
    #         if isinstance(other, Point):
    #             return self.x == other.x and self.y == other.y
    #         return False
    #
    #     def __hash__(self):
    #         return hash((self.x, self.y))  # 使用元组的哈希
    #
    # # 测试
    # p1 = Point(1, 2)
    # p2 = Point(1, 2)
    # print(hash(p1))  # 输出一个整数


# from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, select, and_
# from sqlalchemy.ext.declarative import declarative_base
# from sqlalchemy.orm import sessionmaker, relationship, aliased
#
# Base = declarative_base()
#
#
# class User(Base):
#     __tablename__ = 'users'
#     id = Column(Integer, primary_key=True)
#     name = Column(String)
#     addresses = relationship("Address", back_populates="user")
#
#
# class Address(Base):
#     __tablename__ = 'addresses'
#     id = Column(Integer, primary_key=True)
#     email = Column(String)
#     user_id = Column(Integer, ForeignKey('users.id'))
#     user = relationship("User", back_populates="addresses")
#
#
# # 创建引擎和会话
# engine = create_engine('sqlite:///:memory:')
# Base.metadata.create_all(engine)
# Session = sessionmaker(bind=engine)
# session = Session()
#
# # 示例：查询有特定邮箱地址的用户
# # 首先，创建一个子查询，用于查找具有特定邮箱的地址
# subq = (
#     session.query(Address.user_id)
#     .filter(Address.email == 'example@example.com')
#     .correlate(User)  # 指定子查询中的 Address.user_id 应与外部查询的 User 相关联
#     .subquery()
# )
#
# # 然后，使用这个子查询来查询用户
# query = session.query(User).filter(User.id.in_(subq))
# results = query.all()
#
# for user in results:
#     print(user.name)
# def a(b,**kwargs):
#     print(b)
#     print(kwargs)
# # def b():
# #     a(1)
# #     pass
# # b()
# from sqlalchemy import create_engine, Column, DateTime, Integer, func
# from sqlalchemy.ext.declarative import declarative_base
# from sqlalchemy.orm import sessionmaker
# from datetime import datetime, timedelta
#
# # 数据库连接
# engine = create_engine('sqlite:///records.db')
# Session = sessionmaker(bind=engine)
# session = Session()
#
# Base = declarative_base()
#
#
# class Record(Base):
#     __tablename__ = 'records'
#     id = Column(Integer, primary_key=True)
#     timestamp = Column(DateTime)
#     # 其他字段...
#
#
# # 创建表
# Base.metadata.create_all(engine)
#
#
# def get_week_range(dt):
#     """获取给定日期所在周的开始和结束日期"""
#     start = dt - timedelta(days=dt.weekday())
#     end = start + timedelta(days=6)
#     return start, end
#
#
# def query_records(target_time):
#     """根据给定时间进行本周、本月和本年查询"""
#     # 本周查询
#     week_start, week_end = get_week_range(target_time)
#     week_records = session.query(Record).filter(
#         func.date(Record.timestamp) >= week_start.date(),
#         func.date(Record.timestamp) <= week_end.date()
#     ).all()
#
#     # 本月查询
#     month_records = session.query(Record).filter(
#         func.extract('year', Record.timestamp) == target_time.year,
#         func.extract('month', Record.timestamp) == target_time.month
#     ).all()
#
#     # 本年查询
#     year_records = session.query(Record).filter(
#         func.extract('year', Record.timestamp) == target_time.year
#     ).all()
#
#     return {
#         'week_records': week_records,
#         'month_records': month_records,
#         'year_records': year_records
#     }
#
#
# # 使用示例
# time_str = "2025.04.05 16:37:55"
# target_time = datetime.strptime(time_str, "%Y.%m.%d %H:%M:%S")
# results = query_records(target_time)
#
# print(f"本周记录数: {len(results['week_records'])}")
# print(f"本月记录数: {len(results['month_records'])}")
# print(f"本年记录数: {len(results['year_records'])}")

